package com.mswyt.utils.test.excel;

import com.mswyt.utils.msConverts.MsConvertDataUtils;
import com.mswyt.utils.msExcel.MsExcelInvoke;
import com.mswyt.utils.msExcel.dto.MsDynamicExportDto;
import com.mswyt.utils.msExcel.dto.MsImportDto;
import com.mswyt.utils.msExcel.dto.MsTemplateExportDto;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName: ExcelController
 * @Description:
 */
@RestController
@RequestMapping("/test/excel")
public class ExcelController {

    @PostMapping("/dynamicExport")
    public void dynamicExport(HttpServletResponse response, @RequestBody MsDynamicExportDto dto) throws Exception {
        MsExcelInvoke.dynamicExport(response, dto);
    }


    @PostMapping("/templateExport")
    public void templateExport(HttpServletResponse response, @RequestBody MsTemplateExportDto dto) throws Exception {
        MsExcelInvoke.templateExport(response, dto);
    }


    @PostMapping("/import")
    public Object readExcel(MultipartFile file, @RequestParam Map<String, Object> dto) throws Exception {
         return MsExcelInvoke.importExcel(file, MsConvertDataUtils.mapToBean(dto,MsImportDto.class));
//        List<MsUserExcel> msUserExcels = MsExcelUtils.readExcelBean(MsUserExcel.class, file, 2);
//        return msUserExcels;
    }
}
